﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TruthInLending.aspx.cs" Inherits="Manager_Loan_TruthInLending" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server" RunAt="server">
<LINK rel="stylesheet" type="text/css" href="/CSS/Outlook.css">
<LINK rel="stylesheet" type="text/css" href="/Manager/CSS/CSS.css">
<style>
.RO{FONT-WEIGHT: bold;FONT-SIZE:90%}
</style>
</head>
<body>
    <form id="form1" runat="server">
    <ajaxtk:ToolkitScriptManager runat="server" ></ajaxtk:ToolkitScriptManager>
    <UI:PlaceHolderJS runat="server">
   	<asp:DropDownList id="selSnapshots" runat="server" DataTextField="SnapshotName" DataFieldValue="SnapshotName" datasourceid="dsSnapshots"
   			 dataSrc="#xmlTIL_Snapshot" dataFld="SnapshotName" onchange="doSnapshotName_Changed()" AppendDataBoundItems="true"
   	>
   		<asp:ListItem></asp:ListItem>
   	</asp:DropDownList>
   	<input type="button" value="New" onclick="onNewSnapshot()" id="btnNewSnaphot" runat="server" />
   	<input type="button" value="Delete" onclick="onRemSnapshot()" id="btnRemSnaphot" runat="server" />
   	</UI:PlaceHolderJS>
   	<ajaxtk:HoverMenuExtender TargetControlID="btnNewSnaphot" PopupControlID="hlpNewSnapshot" PopupPosition="Bottom" HoverDelay="500" OffsetX="0" OffsetY="0" runat="server" />
   	<asp:Panel ID="hlpNewSnapshot" runat="server" CssClass="Help">Click to create a new Loan Snapshot.</asp:Panel>
   	<ajaxtk:HoverMenuExtender TargetControlID="btnRemSnaphot" PopupControlID="hlpRemSnapshot" PopupPosition="Bottom" HoverDelay="500" OffsetX="0" OffsetY="0" runat="server" />
   	<asp:Panel ID="hlpRemSnapshot" runat="server" CssClass="Help">Click to delete this Loan Snapshot.</asp:Panel>
		<asp:LinqDataSource ContextTypeName="Data.LINQ.MotoBank" TableName="t_LoanInfo_Snapshots" id="dsSnapshots"
				 Where="LoanID=@LoanID" runat="server">
			<WhereParameters>
				<asp:ControlParameter Name="LoanID" ControlID="dsSnapshots" PropertyName="Page.LoanID" Type="Int32" />
			</WhereParameters>
		</asp:LinqDataSource>

			<ajaxtk:CalendarExtender  OnClientShowing="setInputDate" TargetControlID="txtContractDate" runat="server"/>
			<ajaxtk:CalendarExtender  OnClientShowing="setInputDate" TargetControlID="txtFirstPaymentDate" runat="server"/>
<TABLE border="0" Id="tblTIL_Snapshot">
	<TR><TD nowrap>Principal<TD align="right">$<input dataSrc="#xmlTIL_Snapshot" datafld="Principal" preset="numeric" size="5" class="Numeric" style="overflow-x:visible">
	<TR><TD colspan="2" nowrap># Pmts
				<input dataSrc="#xmlTIL_Snapshot" datafld="NumberOfPayments" style="width:auto;width:4ex" null id="txtLoanTerm" />
				|<b><span dataSrc="#xmlTIL_Snapshot" dataFld="TermInYears"></span></b> Years <select dataSrc="#xmlTIL_Snapshot" dataFld="PaymentsPerYear"><option Value="12">Monthly</option><option Value="24">Semi-Montly</option><option Value="26">Bi-Weekly</option><option Value="52">Weekly</option></select>
	<TR><TD>Contract Date
			<TD align="right"><asp:TextBox dataSrc="#xmlTIL_Snapshot" datafld="ContractDate_F" size="10" style="width:auto" null id="txtContractDate" RunAt="server" />
	<TR><TD>1st Pmt Date
			<TD align="right"><asp:TextBox dataSrc="#xmlTIL_Snapshot" datafld="FirstPaymentDate_F" size="10" style="width:auto" id="txtFirstPaymentDate" runat="server"/></TD>
	<TR><TD nowrap>APR(%)
			<TD align="right">
				<table CellPadding="0" cellspacing="0" Width="100%">
					<col Width="50%" Align="right" /><col width="50%" />
					<tr><td VAlign="middle" class="RO" Align="right">$<span dataSrc="#xmlTIL_Snapshot" datafld="PaymentByAPR" preset="currency" noDollar></span></td>
							<td><INPUT dataSrc="#xmlTIL_Snapshot" datafld="APROverride" numeric style="width:7ex;vertical-align:middle;overflow-x:visible"></td></tr>
				</table>
	<TR><TD VAlign="middle">Payment
			<TD nowrap align="right" VAlign="middle">
				<table CellPadding="0" CellSpacing="0"><tr>
					<td><td VAlign="middle" class="RO"><span dataSrc="#xmlTIL_Snapshot" datafld="APRByPayment"></span>%</td>
					<td><INPUT dataSrc="#xmlTIL_Snapshot" datafld="PaymentOverride" FieldName="PaymentOverride" numeric style="width:7ex;vertical-align:middle"></td>
				</tr></table>
	<TR><TD nowrap>Proceeds<TD align="right"><input dataSrc="#xmlTIL_Snapshot" datafld="Proceeds" preset="currency" size="5" TabIndex="-1" ShowZeros noDollar class="Numeric" style="overflow-x:visible">
	<TR><TD nowrap>Finance Charge<TD class="RO" align="right"><SPAN dataSrc="#xmlTIL_Snapshot" datafld="FinanceCharge" preset="currency" showZeros></SPAN>
	<TR><TD nowrap>Total Of Payments<TD class="RO" align="right"><SPAN dataSrc="#xmlTIL_Snapshot" datafld="TotalPayments" preset="currency" showZeros></SPAN>
	<TR><TD nowrap>AddOn(%)<TD class="RO" align="right"><SPAN dataSrc="#xmlTIL_Snapshot" datafld="AddOnRateByPayment"></SPAN><TD></TD>
</TABLE>
    </form>
	<XML id="xmlPayments" runat="server"></XML>
	<XML id="xmlTIL_Snapshot" runat="server"></XML>
</body>
</html>
<script>
	var UF_TIL_Snapshot = UF_AddCallBacks("UF_TIL_Snapshot",onTIL_Snapshot_Changed);
	var wsInit = { wsName: "DECISION", tagID: "wsDecision" };
	initWS(wsInit, "/manager/underwriting/Decision.asmx", initDecisionWS);
	var tblTIL_Snapshot = $get("tblTIL_Snapshot");
	var xmlTIL_Snapshot = $get("xmlTIL_Snapshot");
	var selSnapshots = $get("selSnapshots");
	var txtAmountFinanced = $get("txtAmountFinanced");
	var wsTIL_Snapshot_Tag;
	var wsTIL_Snapshot_CallService;
	var xmlDOM = new ActiveXObject("Microsoft.XMLDOM");
	attachToKeyDown();
	cropWindow();
	function updateXMLLocal(sXML,parentElenent){
		return updateXML(sXML,parentElenent,[{Select:selSnapshots,Table:"SnapshotsList"}]);
	}
	function updateXML(sXML,parentElenent,selects){
		parentElenent = parentElenent || document.body;
		var xmlTags = parentElenent.all.tags("XML");
		xmlDOM.loadXML(sXML);
		for (var i = 0; i < xmlTags.length; i++) {
			var xmlTable = xmlTags[i].XMLDocument.selectSingleNode("*/*");
			if (!xmlTable) continue;
			if (xmlTags[i].id.search(/^_XML_/)>=0) continue;
			var dsTable = xmlDOM.selectSingleNode("*/" + xmlTable.nodeName);
			if (!dsTable) continue;
			if( !xmlTags[i].loadXML("<DS>" + dsTable.xml + "</DS>") )alert("Error loading "+xmlTable.nodeName);
		}
		selects = selects||[];
		for (var i in selects) {
			var sel = typeof(selects[i]["Select"]) == 'object' ? selects[i]["Select"] : $get(selects[i]["Select"]);
			if (!sel) continue;
			var rs = getRSFromDS(sXML, selects[i]["Table"]);
			if (!rs) continue;
			fillSelect(rs, sel);
		}
	}
	
	function UF_TIL_SnapshotWithSnapshotName() {
		return UF_TIL_Snapshot(undefined, undefined, undefined, undefined, selSnapshots.value);
	}
	function initDecisionWS() {
		wsTIL_Snapshot_CallService = UF_TIL_Snapshot.callService = this[wsInit.wsName].callService;
		wsTIL_Snapshot_Tag = UF_TIL_Snapshot.wsTag = this;
		initInputs(undefined, null, tblTIL_Snapshot, UF_TIL_SnapshotWithSnapshotName);
		initPreset(tblTIL_Snapshot);
	}
	function onNewSnapshot() {
		var snapshotName = prompt("Enter name for new snapshot:", selSnapshots.value);
		if (!snapshotName || snapshotName == selSnapshots.value) return;
		var ret = wsTIL_Snapshot_CallService(CO("xmlTIL_Snapshot_Add", wsTIL_Snapshot_Tag), snapshotName);
		if (showSOAPError(ret)) return false;
		updateXMLLocal(ret.value);
	}
	function onRemSnapshot() {
		var ssn = selSnapshots.value;
		if (!confirm("Delete ["+ssn+"] Snapshot?")) return;
		var ret = wsTIL_Snapshot_CallService(CO("xmlTIL_Snapshot_Remove", wsTIL_Snapshot_Tag), ssn);
		if (showSOAPError(ret)) return false;
		updateXMLLocal(ret.value);
	}
	function onTIL_Snapshot_Changed(ret, el, fieldName, fieldValue, wsMethod) {
		if (!ret) {
			ret = wsTIL_Snapshot_CallService(CO("xmlTIL_Snapshot", wsTIL_Snapshot_Tag), "", "", selSnapshots.value);
			if (showSOAPError(ret)) return false;
		}
		updateXMLLocal(ret.value);
		//if (!xmlTIL_Snapshot.loadXML(ret.value)) alert("Error while loading TIL");
		setTimeout(function() { initPreset(tblTIL_Snapshot); try { document.activeElement.select() } catch (e) { }; }, 500);
	}
	function setInputDate(sender, e) {
		sender._selectedDate = new Date(sender._element.value || new Date());
	}
	function doSnapshotName_Changed() {
		try {
			var ssnPrev = xmlTIL_Snapshot.recordset(selSnapshots.dataFld).value;
		} catch (e) {
			return onTIL_Snapshot_Changed();
		}
		if( !ssnPrev )return;
		var href = location.href.replace(/&ssn.*/i,"")+"&ssn="+selSnapshots.value;
		showModelessDialog(href, { opener: Opener() }, "resizable:1;dialogWidth:300px");
		selSnapshots.value = ssnPrev;
		return false;
	}

//	Sys.Application.add_init(function() {
//		$create(AjaxControlToolkit.MaskedEditBehavior, { //"ClientStateFieldID": "_ClientState",
//			"CultureAMPMPlaceholder": "AM;PM",
//			"CultureCurrencySymbolPlaceholder": "$",
//			"CultureDateFormat": "MDY",
//			"CultureDatePlaceholder": "/",
//			"CultureDecimalPlaceholder": ".",
//			"CultureName": "en-US",
//			"CultureThousandsPlaceholder": ",",
//			"CultureTimePlaceholder": ":",
//			"InputDirection": 1, "Mask": "999,999.99",
//			"MaskType": 2, "id": "ctl07"
//		}, null, null, txtAmountFinanced);
//	});

</script>